import request from '@/utils/request'

/**
 * 创建群聊
 * @param { Array } groupMembers 群聊成员
 * @param { string } groupName 群聊名称
 * @returns {Promise<AxiosResponse<any>>}
 */
export const createGroup = (groupMembers, groupName) => {
  return request.post('group/create', {
    group_members: groupMembers,
    group_name: groupName
  })
}

/**
 * 群聊列表
 * @returns {Promise<AxiosResponse<any>>}
 */
export const groupList = () => {
  return request.get('group/list')
}

/**
 * 获取群聊信息
 * @param { number } groupID 群聊编号
 * @returns {Promise<AxiosResponse<any>>}
 */
export const groupInfo = (groupID) => {
  return request.get(`group/info/${groupID}`)
}

/**
 * 删除群聊最近联系人
 * @param { number } groupID 要删除最近群聊的编号
 * @returns {*}
 */
export const deleteRecentGroup = (groupID) => {
  return request.delete(`group/recent/delete/${groupID}`)
}

/**
 * 群聊人员列表
 * @param { number } groupID 群聊编号
 * @returns {*}
 */
export const groupMemberList = (groupID) => {
  return request.get(`group/members/list/${groupID}`)
}

/**
 * 修改群聊名称
 * @param { number } groupID 群聊编号
 * @param { string } groupName 群聊名称
 * @returns {*}
 */
export const groupUpdate = (groupID, groupName) => {
  return request.put('group/update', {
    group_id: groupID,
    group_name: groupName
  })
}

/**
 * 踢出群聊成员
 * @param { number } groupID 群聊编号
 * @param { array } groupMembers 群成员数组
 * @returns {*}
 */
export const groupMembersDelete = (groupID, groupMembers) => {
  return request.delete('group/members/delete', {
    data: {
      group_id: groupID,
      group_members: groupMembers
    }
  })
}

/**
 * 邀请人员进入群聊
 * @param { number } groupID 群聊编号
 * @param { array } groupMembers 群成员数组
 * @returns {*}
 */
export const groupMembersAdd = (groupID, groupMembers) => {
  return request.put('group/members/add',
    {
      group_id: groupID,
      group_members: groupMembers
    }
  )
}

/**
 * 退出群聊
 * @param { number } groupID 群聊ID
 * @returns {*}
 */
export const groupMemberExit = (groupID) => {
  return request.get(`group/members/exit/${groupID}`)
}

/**
 * 解散群聊
 * @param { number } groupID 解散群聊
 * @returns {*}
 */
export const groupDissolution = (groupID) => {
  return request.put('group/dissolution', {
    group_id: groupID
  })
}

/**
 * 删除群聊消息
 * @param { number } groupID 群聊ID
 * @param {{ array }} groupMessages 消息数组
 * @returns {*}
 */
export const groupMessageDelete = (groupID, groupMessages) => {
  return request.put('group/message/delete', {
    group_id: groupID,
    groupMessages
  })
}

/**
 * 删除群聊全部消息
 * @param {number} groupID 群聊ID
 * @returns {*}
 */
export const groupMessageDeleteAll = (groupID) => {
  return request.delete(`group/message/deleteAll/${groupID}`)
}
